package com.haogu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haogu.entity.*;
import com.haogu.mapper.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class BusinessService implements com.haogu.service.BusinessService {
    @Resource
    private BusinessMapper businessMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private CustomerMapper customerMapper;
    @Resource
    private ContactsMapper contactsMapper;
    @Resource
    private BusinessStatusMapper businessStatusMapper;

    /**
     * 查询所有商机分页
     * @param map
     * @return
     */
    @Override
    public List<VBusiness> listPage(Map map) {
        List<VBusiness> userBusinesses = businessMapper.listPage(map);
        return userBusinesses;
    }

    /**
     * 查询商机表
     * @return
     */
    @Override
    public List<VBusiness> listBusiness() {
        List<VBusiness> businesses = businessMapper.listBusiness();
        return businesses;
    }
    /**
     * 根据id查business
     * @param id
     * @return
     */
    @Override
    public Business selectBusinessById(Integer id){
        Business business = businessMapper.selectBusinessById(id);
        return business;
    }

    /**
     * 查询今日新建
     * @return
     */
    @Override
    public List<VBusiness> selectDay( Map map) {
        List<VBusiness> businesses = businessMapper.selectDay(map);
        return businesses;
    }

    /**
     * 查询商机行数
     * @return
     */
    public int rows(){
        QueryWrapper queryWrapper = new QueryWrapper();
        QueryWrapper name = queryWrapper.select("name");
        Integer count = businessMapper.selectCount(name);
        return count;
    }

    /**
     * 查询User表
     * @return
     */
    public List<User> selectUser(){
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.select("id");
//        queryWrapper.select("username");
        List user = userMapper.selectList(null);
        return user;
    }

    /**
     * 查询Customer表
     * @return
     */

    public List<Customer> selectCustomer(){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.comment("names");
        List customer = customerMapper.selectList(queryWrapper);
        return customer;
    }


    /**
     *查询联系人表
     * @return
     */
    public List<Contacts> selectContacts(){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.comment("id");
        List contacts = contactsMapper.selectList(queryWrapper);
        return contacts;
    }

    /**
     * 查询商机状态表
     * @return
     */
    public List<BusinessStatusMapper> selectBusinessStatusMapper(){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.comment("id");
        List businessStatus = businessStatusMapper.selectList(queryWrapper);
        return businessStatus;
    }

    /**
     * 添加商机
     * @param business
     * @return
     */
    public boolean addBusiness(Business business){
        int i = businessMapper.insert(business);
        if (i == 0){
            return false;
        }
        return true;
    }


    /**
     * 根据id查Customer
     * @param id
     * @return
     */
    public Customer selectCustomerById(Integer id){
        Customer customer = customerMapper.selectById(id);
        return customer;
    }

    /**
     * 根据id查User
     * @param id
     * @return
     */
    @Override
    public User selectUserByUserId(Integer id) {
        User user = userMapper.selectUserByUserId(id);
        return user;
    }

    /**
     * 根据id查Contacts
     * @param id
     * @return
     */
    public Contacts selectContactsById(Integer id){
        Contacts contacts = contactsMapper.selectById(id);
        return contacts;
    }

    /**
     * 根据id查BusinessStatus
     * @param id
     * @return
     */
    public BusinessStatus selectStatusById(Integer id){
        BusinessStatus businessStatus = businessStatusMapper.selectById(id);
        return businessStatus;
    }

    /**
     * 根据id修改Business
     * @param business
     * @return
     */
    public boolean editBusiness(Business business){
        int i = businessMapper.updateById(business);
        if (i == 0){
            return false;
        }
        return true;
    }

    /**
     * 根据id删除Business
     * @param id
     * @return
     */
    public int deleteBusiness(Integer id){
        int i = businessMapper.deleteById(id);
        return i;
    }

    /**
     * 我的商机
     * @param map
     * @return
     */
    @Override
    public List<VBusiness> selectMyBusiness(Map map) {
        List<VBusiness> businesses = businessMapper.selectMyBusiness(map);
        return businesses;
    }

    /**
     * 下属商机
     * @param map
     * @return
     */
    @Override
    public List<VBusiness> selectSubBusiness(Map map) {
        List<VBusiness> subBusiness = businessMapper.selectSubBusiness(map);
        return subBusiness;
    }

    /**
     * 查询删除
     * @param map
     * @return
     */
    @Override
    public List<VBusiness> selectRecycle(Map map) {
        List<VBusiness> recycleBusiness = businessMapper.selectRecycle(map);
        return recycleBusiness;
    }
}
